package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.OrderDetailsBean;

import org.xutils.x;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by admin on 2016/12/15.
 */
public class OrderContentAdapter extends BaseAdapter {
    private Context context;
    private List<OrderDetailsBean> data;

    public OrderContentAdapter(Context context, List<OrderDetailsBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OrderContentViewHolder viewHolder = new OrderContentViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.order_content_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            viewHolder.tv_specification = (TextView) convertView.findViewById(R.id.tv_specification);
            viewHolder.tv_color = (TextView) convertView.findViewById(R.id.tv_color);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.tv_old_price = (TextView) convertView.findViewById(R.id.tv_old_price);
            viewHolder.tv_number = (TextView) convertView.findViewById(R.id.tv_number);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (OrderContentViewHolder) convertView.getTag();
        }
        x.image().bind(viewHolder.iv_img, data.get(position).getGoods_spic());
        viewHolder.tv_content.setText(data.get(position).getGoods_name());
        viewHolder.tv_specification.setText(data.get(position).getSku_info());
        viewHolder.tv_price.setText(data.get(position).getGoods_price());
        DecimalFormat df = new DecimalFormat("######0.00");


//        try {
//            viewHolder.tv_price.setText("¥ " + df.format(Double.parseDouble(data.get(position).getGoods_price()) * Double.parseDouble(MyApplication.getInstance().getUserBean().getRatio().toString())));
//        } catch (Exception e) {
        viewHolder.tv_price.setText("¥ " + df.format(Double.parseDouble(data.get(position).getGoods_price())));
//        }

        viewHolder.tv_old_price.setText(data.get(position).getOldprice());
        viewHolder.tv_number.setText("x" + data.get(position).getGoods_nums());

        viewHolder.tv_old_price.getPaint().setAntiAlias(true);//抗锯齿
        viewHolder.tv_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        return convertView;
    }

    class OrderContentViewHolder {
        ImageView iv_img;
        TextView tv_content;
        TextView tv_specification;
        TextView tv_color;
        TextView tv_price;
        TextView tv_old_price;
        TextView tv_number;
    }
}
